/*     */ package xin.petstore.framework.cas;
/*     */ 
/*     */ import java.io.FileInputStream;
/*     */ import java.io.IOException;
/*     */ import java.util.Properties;
/*     */ import javax.net.ssl.HostnameVerifier;
/*     */ import org.jasig.cas.client.proxy.Cas20ProxyRetriever;
/*     */ import org.jasig.cas.client.proxy.ProxyGrantingTicketStorage;
/*     */ import org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl;
/*     */ import org.jasig.cas.client.ssl.AnyHostnameVerifier;
/*     */ import org.jasig.cas.client.ssl.HttpURLConnectionFactory;
/*     */ import org.jasig.cas.client.ssl.HttpsURLConnectionFactory;
/*     */ import org.jasig.cas.client.util.CommonUtils;
/*     */ import org.jasig.cas.client.util.ReflectUtils;
/*     */ import org.jasig.cas.client.validation.Cas20ProxyTicketValidator;
/*     */ import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
/*     */ import org.jasig.cas.client.validation.TicketValidator;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.FactoryBean;
/*     */ 
/*     */ public class TicketValidatorFactoryBean
/*     */   implements FactoryBean<TicketValidator>
/*     */ {
/*  25 */   protected final Logger logger = LoggerFactory.getLogger(getClass());
/*     */   private boolean allowAnyProxy;
/*     */   private String allowedProxyChains;
/*     */   private String casServerUrlPrefix;
/*  33 */   private ProxyGrantingTicketStorage proxyGrantingTicketStorage = new ProxyGrantingTicketStorageImpl();
/*     */ 
/*  35 */   private boolean renew = Boolean.FALSE.booleanValue();
/*     */   private String proxyCallbackUrl;
/*     */   private String encoding;
/*  41 */   private String hostnameVerifier = AnyHostnameVerifier.class.getName();
/*     */   private String hostnameVerifierConfig;
/*     */   private String sslConfigFile;
/*     */ 
/*     */   public void setAllowAnyProxy(boolean allowAnyProxy)
/*     */   {
/*  48 */     this.allowAnyProxy = allowAnyProxy;
/*     */   }
/*     */ 
/*     */   public void setAllowedProxyChains(String allowedProxyChains) {
/*  52 */     this.allowedProxyChains = allowedProxyChains;
/*     */   }
/*     */ 
/*     */   public void setCasServerUrlPrefix(String casServerUrlPrefix)
/*     */   {
/*  57 */     this.casServerUrlPrefix = casServerUrlPrefix;
/*     */   }
/*     */ 
/*     */   public void setProxyGrantingTicketStorage(ProxyGrantingTicketStorage proxyGrantingTicketStorage)
/*     */   {
/*  63 */     this.proxyGrantingTicketStorage = proxyGrantingTicketStorage;
/*     */   }
/*     */ 
/*     */   public void setRenew(boolean renew)
/*     */   {
/*  68 */     this.renew = renew;
/*     */   }
/*     */ 
/*     */   public void setProxyCallbackUrl(String proxyCallbackUrl)
/*     */   {
/*  73 */     this.proxyCallbackUrl = proxyCallbackUrl;
/*     */   }
/*     */ 
/*     */   public void setEncoding(String encoding)
/*     */   {
/*  78 */     this.encoding = encoding;
/*     */   }
/*     */ 
/*     */   public void setHostnameVerifier(String hostnameVerifier)
/*     */   {
/*  83 */     this.hostnameVerifier = hostnameVerifier;
/*     */   }
/*     */ 
/*     */   public void setHostnameVerifierConfig(String hostnameVerifierConfig)
/*     */   {
/*  88 */     this.hostnameVerifierConfig = hostnameVerifierConfig;
/*     */   }
/*     */ 
/*     */   public void setSslConfigFile(String sslConfigFile)
/*     */   {
/*  93 */     this.sslConfigFile = sslConfigFile;
/*     */   }
/*     */ 
/*     */   public TicketValidator getObject()
/*     */     throws Exception
/*     */   {
/*     */     Cas20ServiceTicketValidator validator;
/*     */     Cas20ServiceTicketValidator validator;
/* 102 */     if ((this.allowAnyProxy) || (CommonUtils.isNotBlank(this.allowedProxyChains))) {
/* 103 */       Cas20ProxyTicketValidator v = new Cas20ProxyTicketValidator(this.casServerUrlPrefix);
/* 104 */       v.setAcceptAnyProxy(this.allowAnyProxy);
/* 105 */       v.setAllowedProxyChains(CommonUtils.createProxyList(this.allowedProxyChains));
/* 106 */       validator = v;
/*     */     } else {
/* 108 */       validator = new Cas20ServiceTicketValidator(this.casServerUrlPrefix);
/*     */     }
/* 110 */     validator.setProxyCallbackUrl(this.proxyCallbackUrl);
/* 111 */     validator.setProxyGrantingTicketStorage(this.proxyGrantingTicketStorage);
/*     */ 
/* 113 */     HttpURLConnectionFactory factory = new HttpsURLConnectionFactory(
/* 114 */       getHostnameVerifier(), getSSLConfig());
/* 115 */     validator.setURLConnectionFactory(factory);
/*     */ 
/* 117 */     validator.setProxyRetriever(
/* 118 */       new Cas20ProxyRetriever(this.casServerUrlPrefix, this.encoding, factory));
/* 119 */     validator.setRenew(this.renew);
/* 120 */     validator.setEncoding(this.encoding);
/*     */ 
/* 122 */     return validator;
/*     */   }
/*     */ 
/*     */   protected Properties getSSLConfig()
/*     */   {
/* 134 */     Properties properties = new Properties();
/*     */ 
/* 136 */     if (this.sslConfigFile != null) {
/* 137 */       FileInputStream fis = null;
/*     */       try {
/* 139 */         fis = new FileInputStream(this.sslConfigFile);
/* 140 */         properties.load(fis);
/* 141 */         this.logger.trace("Loaded {} entries from {}", Integer.valueOf(properties.size()), 
/* 142 */           this.sslConfigFile);
/*     */       } catch (IOException ioe) {
/* 144 */         this.logger.error(ioe.getMessage(), ioe);
/*     */       } finally {
/* 146 */         CommonUtils.closeQuietly(fis);
/*     */       }
/*     */     }
/* 149 */     return properties;
/*     */   }
/*     */ 
/*     */   protected HostnameVerifier getHostnameVerifier()
/*     */   {
/* 158 */     if (this.hostnameVerifier != null) {
/* 159 */       if (this.hostnameVerifierConfig != null) {
/* 160 */         return (HostnameVerifier)ReflectUtils.newInstance(this.hostnameVerifier, new Object[] { this.hostnameVerifierConfig });
/*     */       }
/* 162 */       return (HostnameVerifier)ReflectUtils.newInstance(this.hostnameVerifier, new Object[0]);
/*     */     }
/*     */ 
/* 165 */     return null;
/*     */   }
/*     */ 
/*     */   public Class<?> getObjectType() {
/* 169 */     return TicketValidator.class;
/*     */   }
/*     */ 
/*     */   public boolean isSingleton()
/*     */   {
/* 174 */     return true;
/*     */   }
/*     */ }

/* Location:           C:\java代码反编译器\core-1.1.4.jar
 * Qualified Name:     com.eloancn.framework.cas.TicketValidatorFactoryBean
 * JD-Core Version:    0.6.0
 */